package com.jdyfy.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jdyfy.entity.Meet;
import com.jdyfy.entity.Project;
import com.jdyfy.mapper.MeetMapper;
import com.jdyfy.result.Result;
import com.jdyfy.service.MeetService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/jdyfy")
@Slf4j
public class MeetController {

    @Autowired
    private MeetService meetService;

    @Autowired
    private MeetMapper meetMapper;

    // 新增或修改会议
    @PostMapping("/meet/save")
    public Boolean saveOrUpdate(@RequestBody Meet meet) {
        return meetService.saveOrUpdate(meet);
    }

    // 查询所有会议
    @GetMapping("/meets")
    public Result<List<Meet>> getAllMeet() {
        List<Meet> meet = meetService.list();
        return Result.success(meet);
    }

    // 根据状态查询会议
    @GetMapping("/meetsBySome")
    public Result<List<Meet>> meetsBySome(@RequestParam String meetLoca,
                                          @RequestParam String projectName,
                                          @RequestParam String contactPerson,
                                          @RequestParam Integer status) {
        //创建查询对象
        QueryWrapper<Meet> queryWrapper = new QueryWrapper<>();

        //添加条件查询
        if (meetLoca != null && !meetLoca.isEmpty()) {
            queryWrapper.like("meet_loca", meetLoca);
        }
        if (projectName != null && !projectName.isEmpty()) {
            queryWrapper.like("project_name", projectName);
        }
        //like为匹配到该数据
        if (contactPerson != null && !contactPerson.isEmpty()) {
            queryWrapper.like("contact_person", contactPerson);
        }

        queryWrapper.eq("status", status);

        List<Meet> meetList = meetMapper.selectList(queryWrapper);

        return Result.success(meetList);
    }

    @GetMapping("/meetByProjectName")
    public Result<Meet> getMeetByProjectName(String projectName) {
        Meet meet = meetService.getMeetByProjectName(projectName);
        return Result.success(meet);
    }
}
